int calculate(char *s) {
    int n = strlen(s);
    int *stack = (int *)malloc(n * sizeof(int));  // 栈
    int top = -1;  // 栈顶指针
    int num = 0;  // 当前数字
    
    char sign = '+';  // 当前操作符
    
    for (int i = 0; i < n; i++) {
        char c = s[i];
        
        if (isdigit(c)) {
            num = num * 10 + (c - '0');
        }
        
        if (!isdigit(c) && c != ' ' || i == n - 1) {
            if (sign == '+') {
                stack[++top] = num;
            } else if (sign == '-') {
                stack[++top] = -num;
            } else if (sign == '*') {
                stack[top] *= num;
            } else if (sign == '/') {
                stack[top] /= num;
            }
            
            num = 0;  // 重置num
            sign = c;  // 更新操作符
        }
    }
    
    int result = 0;
    for (int i = 0; i <= top; i++) {
        result += stack[i];
    }
    
    free(stack);
    return result;
}